﻿using System;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Windows.Forms;

namespace WriteForFighting.Game
{
    public partial class FormErrorInfo : Form
    {
        public FormErrorInfo(Exception e, string message)
        {
            InitializeComponent();
            List<string> errorInfo = new List<string>
                            {
                                message,
                                "",
                                DateTime.Now + "",
                                "Version: " + GD.VERSION,
                                "OS: " + Environment.OSVersion.VersionString,
                                "共通言語ランタイムバージョン: " + RuntimeEnvironment.GetSystemVersion(),
                                ""
                            };

            List<string> exceptions = new List<string>((e.ToString().Split('\n')));
            exceptions.Add("");

            if (e is ReflectionTypeLoadException)
            {
                exceptions.Add("LoaderExceptions:");
                exceptions.Add("");

                foreach (Exception le in
                    ((ReflectionTypeLoadException)e).LoaderExceptions)
                {
                    exceptions.AddRange(le.ToString().Split('\n'));
                    exceptions.Add("");
                }
            }

            if (e.InnerException != null)
            {
                exceptions.Add("InnerException:");
                exceptions.Add("");
                exceptions.AddRange(e.InnerException.ToString().Split('\n'));
            }

            errorInfo.AddRange(exceptions);
            textBox1.Lines = errorInfo.ToArray();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void textBoxEnter(object sender, EventArgs e)
        {
            textBox1.SelectAll();
        }
    }
}
